namespace LS.UGFUnits
{
    using Unity.VisualScripting;

    public sealed class GetLocalizationString : LocalizationUnit
    {
        [DoNotSerialize] [PortLabelHidden] public ValueInput Key { get; private set; }

        [DoNotSerialize] [PortLabelHidden] public ValueOutput Value { get; private set; }

        protected override void Definition()
        {
            base.Definition();
            Key = ValueInput<string>(nameof(Key), string.Empty);
            Value = ValueOutput<string>(nameof(Value));
        }

        protected override ControlOutput In(Flow flow)
        {
            string key = flow.GetValue<string>(Key);
            string text = Target?.GetString(key) ?? string.Empty;
            flow.SetValue(Value, text);
            return base.In(flow);
        }
    }

    public abstract class GetLocalizationString_MutilArgs : LocalizationUnit
    {
        protected abstract int Count { get; }

        [DoNotSerialize] [PortLabelHidden] public ValueInput Key { get; private set; }

        [DoNotSerialize] [PortLabelHidden] public ValueInput[] Args { get; private set; }

        [DoNotSerialize] [PortLabelHidden] public ValueOutput Value { get; private set; }

        protected override void Definition()
        {
            base.Definition();
            Key = ValueInput<string>(nameof(Key), string.Empty);
            Args = new ValueInput[Count];
            for (int i = 0; i < Count; i++)
            {
                Args[i] = ValueInput<string>($"Arg{i}", string.Empty);
            }

            Value = ValueOutput<string>(nameof(Value));
        }

        protected override ControlOutput In(Flow flow)
        {
            string key = flow.GetValue<string>(Key);
            string text = string.Empty;
            switch (Count)
            {
                case 1:
                    text = Target?.GetString(key, Args[0]) ?? string.Empty;
                    break;
                case 2:
                    text = Target?.GetString(key, Args[0], Args[1]) ?? string.Empty;
                    break;
                case 3:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2]) ?? string.Empty;
                    break;
                case 4:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3]) ?? string.Empty;
                    break;
                case 5:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4]) ?? string.Empty;
                    break;
                case 6:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5]) ?? string.Empty;
                    break;
                case 7:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6]) ??
                           string.Empty;
                    break;
                case 8:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7]) ?? string.Empty;
                    break;
                case 9:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7], Args[8]) ?? string.Empty;
                    break;
                case 10:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7], Args[8], Args[9]) ?? string.Empty;
                    break;
                case 11:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7], Args[8], Args[9], Args[10]) ?? string.Empty;
                    break;
                case 12:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7], Args[8], Args[9], Args[10], Args[11]) ?? string.Empty;
                    break;
                case 13:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7], Args[8], Args[9], Args[10], Args[11], Args[12]) ?? string.Empty;
                    break;
                case 14:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                        Args[7], Args[8], Args[9], Args[10], Args[11], Args[12], Args[13], Args[14]) ?? string.Empty;
                    break;
                case 15:
                    text = Target?.GetString(key, Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6],
                               Args[7], Args[8], Args[9], Args[10], Args[11], Args[12], Args[13], Args[14], Args[15]) ??
                           string.Empty;
                    break;

                default:
                    break;
            }

            flow.SetValue(Value, text);
            return base.In(flow);
        }

        public sealed class GetLocalizationString_1Args : GetLocalizationString_MutilArgs
        {
            protected override int Count => 1;
        }

        public sealed class GetLocalizationString_2Args : GetLocalizationString_MutilArgs
        {
            protected override int Count => 2;
        }
        public sealed class GetLocalizationString_3Args : GetLocalizationString_MutilArgs
        {
            protected override int Count => 3;
        }
        public sealed class GetLocalizationString_4Args : GetLocalizationString_MutilArgs
        {
            protected override int Count => 4;
        }
        public sealed class GetLocalizationString_5Args : GetLocalizationString_MutilArgs
        {
            protected override int Count => 5;
        }
        public sealed class GetLocalizationString_6Args : GetLocalizationString_MutilArgs
        {
            protected override int Count => 6;
        }
    }
}